define(["labs","lab"],function(labs,lab){
    function init() {
        var head = getModule();
        addEvent(head);
        $('body').append(head);
    };

    function addEvent(module) {
        //$(module).find('.dropdown-toggle').dropdown();
        module.find("[data-href='labs']").click(function() {
            lab.remove();
            labs.init(true);
        });
        module.find("[data-href='my']").click(function() {
            my();
        });
        module.find("[data-href='setup']").click(function(){
            setup();
        });
    }

    function getModule() {
        var head;
        $.ajax({
            async : false,
            method : 'GET',
            url : 'app/head/header.html',
            datType : 'string',
            success : function(response){
                if(typeof(response) === 'string'){
                    head = response;
                };
            }
        });
        return $(head);
    }

    function my(){
        var my = getMyModule();
        my.appendTo('body');
        my.on('hidden.bs.modal', function (e) {
            my.remove();
        })
    }

    function getMyModule() {
        var my;
        $.ajax({
            async : false,
            method : 'GET',
            url : 'app/head/my/my.html',
            datType : 'string',
            success : function(response){
                if(typeof(response) === 'string'){
                    my = response;
                }
            }
        });
        return $(my);
    }

    function setup() {
        var setup = getSetupModule();
        setup.appendTo("body");
        setup.on('hidden.bs.modal', function (e) {
            setup.remove();
        })
    }

    function getSetupModule() {
        var setup;
        $.ajax({
            async : false,
            method : 'GET',
            url : 'app/head/setup/setup.html',
            datType : 'string',
            success : function(response){
                if(typeof(response) === 'string'){
                    setup = response;
                }
            }
        });
        return $(setup);
    }

    return {
        init : init
    }
});